'use strict';

// const mongoose = require('mongoose');

module.exports = function (mongoose, Schema) {

    let schema = new Schema({
        title: {
            $type: String,
            required: true,
        },
        content: String,
        summary: String,  //摘要
        imgKey: String,   //阿里云存储的key
        status: Number,   //5发布状态
        publishedAt: {
            $type: Date,//发布时间
            required: true,
        },
        editor: String,   //采编人
        verifier: String, //审核人
        publisher: String,//发布人
        author: String,   //作者
        source: String,   //来源
        keyword: {
            force:   String,//强制词
            similar: {
                $type: String,//近义词
                required: true,
            },
            antonym: String,//歧义词
        },
        stocks: [],//股票的内码
        themes: [],//题材的内码
        freeEffect: {//可以免费查看影响力
            $type: Boolean,
            default: false,
        },
    }, {collection: 'top_info', timestamps: true, typeKey: '$type'});

    schema.index({publishedAt: 1});
    schema.index({themes: 1});

//马金星说就叫这个名字，我去2016-03-09
    schema.virtual('timestamp')
        .get(function() {
            return +this.publishedAt;
        });

    schema.virtual('smallImgKey')
        .get(function(){
            return this.imgKey.replace('.jpg', '_s.jpg');
        });

    schema.set('toObject', {virtuals: true});
    schema.set('toJSON', {virtuals: true});

    return mongoose.model('TopInfo', schema)
};
